import json
import requests


class HttpRequest:
    def __init__(self):
        self.request = self.send_http_request
        self.json = json.loads

    def send_http_request(self, url, method='GET', headers=None, data=None, params=None):
        if headers is None:
            headers = {}
        _headers = headers.copy()
        _headers.update(
            {'User-Agent': 'Mozilla/5.0(Windows;U;Windows NT6.1;en-US;rv:1.9.1.6) Geko/20091201 Firefox/3.5.6'})
        session = requests.Session()

        response = session.request(
            method,
            url,
            headers=_headers,
            data=data,
            params=params,
            verify=False
        )
        print("response.url>>>", response.url)
        if response.status_code == 200:
            return response.text
        else:
            return json.dumps({
                "code": response.status_code,
                "msg": response.text
            })
